package job._20240325meituan;

import util.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @Project : algorithm-learning-java
 * @Author : Ruoyu Wang
 * @User : Momenta
 * @DateTime : 2024/3/27 15:21
 */
public class Q1 {
    List<List<Integer>> res = new ArrayList<>();

    void dfs(TreeNode node, int k) {
        if (node == null) return;
        if (res.size() < k) res.add(new ArrayList<>());
        res.get(k - 1).add(node.val);
        dfs(node.left, k + 1);
        dfs(node.right, k + 1);
    }

    public static void main(String[] args) {
        Q1 sl = new Q1();
        TreeNode root = job._20240327meituan.Q1.createTreeByPreorderAndInorder(new int[]{1, 2, 4, 5, 3, 6, 7}, new int[]{4, 2, 5, 1, 6, 3, 7});
        sl.dfs(root, 1);
        System.out.println(sl.res);
    }
}
